<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>报表维护</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 移动设备 viewport -->
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
    <meta name="author" content="admui.com">
    <!-- 360浏览器默认使用Webkit内核 -->
    <meta name="renderer" content="webkit">
    <!-- 禁止搜索引擎抓取 -->
    <meta name="robots" content="nofollow">
    <!-- 禁止百度SiteAPP转码 -->
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <!-- Chrome浏览器添加桌面快捷方式（安卓） -->
    <meta name="mobile-web-app-capable" content="yes">
    <!-- Safari浏览器添加到主屏幕（IOS） -->

    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Admui">

    <meta name="msapplication-TileColor" content="#62a8ea">
    <script src="../public/js/vendor/jquery/jquery.min.js" th:src="@{/js/vendor/jquery/jquery.min.js}"></script>
    <script src="../public/js/vendor/jquery-validation/jquery.validate.min.js"
            th:src="@{/js/vendor/jquery-validation/jquery.validate.min.js}"></script>

    <link rel="stylesheet" href="../public/js/layui/css/layui.css" th:href="@{/js/layui/css/layui.css}">
    <script src="../public/js/layui/layui.all.js" th:src="@{/js/layui/layui.all.js}"></script>
    <script src="../public/js/layui/layui.all.js" th:src="@{/js/layui/layui.js}"></script>

    <style>
        .logo-pic {
            float: left;
            height: 43px;
            margin-top: 5px;
            margin-left: 5px;
        }

        .school-name {
            position: fixed;
            top: 32px;
            left: 97px;
            font-size: 10px;
            font-weight: 600;
            line-height: 14px;
            margin-left: -45px;
            color: #eeeeee;

        }

        .rightmenu {
            position: absolute;
            width: 80px;
            z-index: 9999;
            display: none;
            background-color: #fff;
            padding: 2px;
            color: #333;
            border: 1px solid #eee;
            border-radius: 2px;
            cursor: pointer;
        }

        .rightmenu li {
            text-align: center;
            display: block;
            height: 25px;
            line-height: 25px;
        }

        .rightmenu li:hover {
            background-color: #0d71f5;
            color: #fff;
        }


        .layui-tab-title li:hover {
            background-color: #009688;
            color: white;
        }

        .layui-tab-titleAdd {
            background-color: #009688;
            color: white;
        }
        .title {
            font-family: "华文细黑";
            background:url("./images/title.png") no-repeat;
            background-size: 100%;
        }
    </style>
</head>

<body class="layui-layout-body">

<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo title"></div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <!-- <ul class="layui-nav layui-layout-left">
             <li class="layui-nav-item">
                 <a href="">控制台</a>
             </li>
             <li class="layui-nav-item">
                 <a href="">商品管理</a>
             </li>
             <li class="layui-nav-item">
                 <a href="">用户</a>
             </li>
             <li class="layui-nav-item">
                 <a href="javascript:;">其它系统</a>
                 <dl class="layui-nav-child">
                     <dd>
                         <a href="">邮件管理</a>
                     </dd>
                     <dd>
                         <a href="">消息管理</a>
                     </dd>
                     <dd>
                         <a href="">授权管理</a>
                     </dd>
                 </dl>
             </li>
         </ul>-->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;" id="loginName">
                    admin
                </a>
                <dl class="layui-nav-child">
                    <dd>
                        <a href="">基本资料</a>
                    </dd>
                    <dd>
                        <a href="">安全设置</a>
                    </dd>
                </dl>
            </li>
            <li class="layui-nav-item">
                <a href="">退出</a>
            </li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test" id="nav">
            </ul>
        </div>
    </div>

    <div class="layui-body" id="container">
        <div class="layui-tab" lay-filter="demo" lay-allowclose="true" style="margin:0; background-color:white;">
            <ul class="layui-tab-title"></ul>
            <div class="layui-tab-content"></div>
        </div>
    </div>
    <ul class="right">
        <div class="layui-footer">
            <!-- 底部固定区域 -->
            © layui.com - 底部固定区域
        </div>
    </ul>
    <!-- 鼠标右键-->

    <ul class="rightmenu">
        <li data-type="closethis">关闭当前</li>
        <li data-type="closeall">关闭所有</li>
    </ul>


</div>
<script th:inline="none">

    $.get("/admin/menu", function (res) {

        if (res.code == 0) {
            var data = res.data;
            var menu = ""//定义变量存储
            for (var i = 0; i < data.length; i++) {
                menu += '<li class="layui-nav-item ">';
                if (data[i].parentMenuId == "0") {
                    menu += ' <a href="javascript:;" >' + data[i].menuName + '</a>'
                    for (var j = 0; j < data.length; j++) {
                        var thirdLev = data[j];
                        if (thirdLev.parentMenuId == data[i].menuId) {
                            menu += '<dl class="layui-nav-child" data-id="' + thirdLev.menuId + '" data-url="' + thirdLev.menuUrl + '" data-title="' + thirdLev.menuName + '">'
                            menu += '<dd>'
                            menu += '<a target="option">' + '   ' + thirdLev.menuName + '</a>';
                            menu += '</dd>'
                            menu += "</dl>"
                        }
                    }
                }
                menu += "</li>"
            }
            $("#nav").html(menu);
            $("#nav li:eq(0)").removeClass("layui-nav-item").addClass("layui-nav-item layui-nav-itemed")


            /*
             var data = [
                 {
                     "menuId": "1001",
                     "menuName": "车费管理",
                     "menuUrl": "/carmgr/index",
                     "parentMenuId": "0",
                     "menuImg": ""
                 },{
                     "menuId": "1001001",
                     "menuName": "定价管理",
                     "menuUrl": "/carmgr/index",
                     "parentMenuId": "1001",
                     "menuImg": ""
                 }, {
                     "menuId": "1002",
                     "menuName": "收费管理",
                     "menuUrl": "/feemgr/index",
                     "parentMenuId": "0",
                     "menuImg": ""
                 }, {
                     "menuId": "1002001",
                     "menuName": "收费定价管理",
                     "menuUrl": "/charge/index",
                     "parentMenuId": "1002",
                     "menuImg": ""
                 } , {
                     "menuId": "1002002",
                     "menuName": "收费类型管理",
                     "menuUrl": "/charge/type",
                     "parentMenuId": "1002",
                     "menuImg": ""
                 } ,{
                     "menuId": "1004",
                     "menuName": "发票管理",
                     "menuUrl": "",
                     "parentMenuId": "0",
                     "menuImg": ""
                 }, {
                     "menuId": "1004001",
                     "menuName": "发票维护",
                     "menuUrl": "",
                     "parentMenuId": "1004",
                     "menuImg": ""
                 }, {
                     "menuId": "1004002",
                     "menuName": "发票回收",
                     "menuUrl": "",
                     "parentMenuId": "1004",
                     "menuImg": ""
                 }, {
                     "menuId": "1004003",
                     "menuName": "发票对账",
                     "menuUrl": "",
                     "parentMenuId": "1004",
                     "menuImg": ""
                 }]*/

            var menu = ""//定义变量存储
            for (var i = 0; i < data.length; i++) {
                menu += '<li class="layui-nav-item ">';
                if (data[i].parentMenuId == "0") {
                    menu += ' <a href="javascript:;" >' + data[i].menuName + '</a>'
                    for (var j = 0; j < data.length; j++) {
                        var thirdLev = data[j];
                        if (thirdLev.parentMenuId == data[i].menuId) {
                            menu += '<dl class="layui-nav-child" data-id="' + thirdLev.menuId + '" data-url="' + thirdLev.menuUrl + '" data-title="' + thirdLev.menuName + '">'
                            menu += '<dd>'
                            menu += '<a target="option">' + '   ' + thirdLev.menuName + '</a>';
                            menu += '</dd>'
                            menu += "</dl>"
                        }
                    }
                }
                menu += "</li>"
            }
            $("#nav").html(menu);
            $("#nav li:eq(0)").removeClass("layui-nav-item").addClass("layui-nav-item layui-nav-itemed")

            layui.use('element', function () {
                var $ = layui.jquery;
                var element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块


                //触发事件
                var active = {
                    //在这里给active绑定几项事件，后面可通过active调用这些事件
                    tabAdd: function (url, id, name) {
                        //新增一个Tab项 传入三个参数，分别对应其标题，tab页面的地址，还有一个规定的id，是标签中data-id的属性值
                        //关于tabAdd的方法所传入的参数可看layui的开发文档中基础方法部分
                        element.tabAdd('demo', {
                            title: name,
                            //content: '<iframe data-frameid="' + id + '" scrolling="auto" frameborder="0" src="' + url + '.html" style="width:100%;height:99%;"></iframe>',
                            content: '<iframe data-frameid="' + id + '" scrolling="auto" frameborder="0" src="' + url + '" style="width:100%;height:99%;"></iframe>',
                            id: id //规定好的id
                        })
                        CustomRightClick(id); //给tab绑定右击事件
                        FrameWH();  //计算ifram层的大小
                    },
                    tabChange: function (id) {
                        //切换到指定Tab项
                        element.tabChange('demo', id); //根据传入的id传入到指定的tab项
                    },
                    tabDelete: function (id) {
                        element.tabDelete("demo", id);//删除
                    }
                    , tabDeleteAll: function (ids) {//删除所有
                        $.each(ids, function (i, item) {
                            element.tabDelete("demo", item); //ids是一个数组，里面存放了多个id，调用tabDelete方法分别删除
                        })
                    }
                };


                //左侧菜单栏中内容 ，触发点击事件
                $('#nav .layui-nav-child').on('click', function () {
                    var dataid = $(this);

                    //这时会判断右侧.layui-tab-title属性下的有lay-id属性的li的数目，即已经打开的tab项数目
                    if ($(".layui-tab-title li[lay-id]").length <= 0) {
                        //如果比零小，则直接打开新的tab项
                        active.tabAdd(dataid.attr("data-url"), dataid.attr("data-id"), dataid.attr("data-title"));
                    } else {
                        //否则判断该tab项是否以及存在

                        var isData = false; //初始化一个标志，为false说明未打开该tab项 为true则说明已有
                        $.each($(".layui-tab-title li[lay-id]"), function () {
                            //如果点击左侧菜单栏所传入的id 在右侧tab项中的lay-id属性可以找到，则说明该tab项已经打开
                            if ($(this).attr("lay-id") == dataid.attr("data-id")) {
                                isData = true;
                            }
                        })
                        if (isData == false) {
                            //标志为false 新增一个tab项
                            active.tabAdd(dataid.attr("data-url"), dataid.attr("data-id"), dataid.attr("data-title"));
                        }
                    }
                    //最后不管是否新增tab，最后都转到要打开的选项页面上
                    active.tabChange(dataid.attr("data-id"));
                });

                function CustomRightClick(id) {
                    //取消右键  rightmenu属性开始是隐藏的 ，当右击的时候显示，左击的时候隐藏
                    $('.layui-tab-title li').on('contextmenu', function () {
                        return false;
                    })
                    $('.layui-tab-title,.layui-tab-title li').click(function () {
                        $('.rightmenu').hide();
                    });
                    //桌面点击右击
                    $('.layui-tab-title li').on('contextmenu', function (e) {
                        var popupmenu = $(".rightmenu");
                        popupmenu.find("li").attr("data-id", id); //在右键菜单中的标签绑定id属性

                        //判断右侧菜单的位置
                        l = ($(document).width() - e.clientX) < popupmenu.width() ? (e.clientX - popupmenu.width()) : e.clientX;
                        t = ($(document).height() - e.clientY) < popupmenu.height() ? (e.clientY - popupmenu.height()) : e.clientY;
                        popupmenu.css({left: l, top: t}).show(); //进行绝对定位
                        //alert("右键菜单")
                        return false;
                    });
                }


                $(".rightmenu li").on("click", function () {
                    //右键菜单中的选项被点击之后，判断type的类型，决定关闭所有还是关闭当前。
                    if ($(this).attr("data-type") == "closethis") {
                        //如果关闭当前，即根据显示右键菜单时所绑定的id，执行tabDelete
                        active.tabDelete($(this).attr("data-id"))
                    } else if ($(this).attr("data-type") == "closeall") {
                        var tabtitle = $(".layui-tab-title li");
                        var ids = new Array();
                        $.each(tabtitle, function (i) {
                            ids[i] = $(this).attr("lay-id");
                        })
                        //如果关闭所有 ，即将所有的lay-id放进数组，执行tabDeleteAll
                        active.tabDeleteAll(ids);
                    }

                    $('.rightmenu').hide(); //最后再隐藏右键菜单
                })


                function FrameWH() {
                    var h = $(window).height() - 41 - 10 - 60 - 10 - 44 - 10;
                    $("iframe").css("height", h + "px");
                }

                $(window).resize(function () {
                    FrameWH();
                })
            });

            function CustomRightClick(id) {
                //取消右键
                $('.layui-tab-title li').on('contextmenu', function () {
                    return false;
                })
                $('.layui-tab-title,.layui-tab-title li').click(function () {
                    $('.rightmenu').hide();
                });
                //桌面点击右击
                $('.layui-tab-title li').on('contextmenu', function (e) {
                    var popupmenu = $(".rightmenu");
                    popupmenu.find("li").attr("data-id", id);
                    l = ($(document).width() - e.clientX) < popupmenu.width() ? (e.clientX - popupmenu.width()) : e.clientX;
                    t = ($(document).height() - e.clientY) < popupmenu.height() ? (e.clientY - popupmenu.height()) : e.clientY;
                    popupmenu.css({left: l, top: t}).show();
                    //alert("右键菜单")
                    return false;
                });
            }
        } else {

        }
    })
</script>

</body>
</html>